using System;
using System.Collections.Generic;
using System.Text;

namespace usm.SolDev.Common.Constants
{
    public class Permissions
    {
        #region permission constants
        public enum UserPermission 
        {
            /// <summary>
            ///     Allow the user to view the group projects
            /// </summary>
            ViewGroupsProjects = 1,

            /// <summary>
            ///     Modify group project
            /// </summary>
            ModifyGroupProject = 2,

            /// <summary>
            ///     Allow the user to manage users (create, delete and modify)
            /// </summary>
            ManageUsers = 3,

        }
        #endregion

        #region private fields
        private UserPermission id;
        private string name;
        private string description;
        #endregion

        #region Public properties
        
        /// <summary>
        ///     The permission id
        /// </summary>
        public UserPermission Id
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        ///     The permission name
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        ///     The rule description
        /// </summary>
        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        #endregion

        #region Ctor's
        /// <summary>
        /// Default constructor
        /// </summary>
        public Permissions () {}

        /// <summary>
        ///     Initialization constructor
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        public Permissions(UserPermission id, string name, string description)
        {
            this.id = id;
            this.name = name;
            this.description = description;
        }

        #endregion
    
        #region Static helpers

        /// <summary>
        ///     Get permission descriptor by it's numerical Id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Permissions GePermitionDescriptor (int id, List <Permissions> permissions)
        {
            foreach(Permissions permition in permissions)
            {
                if (permition.Id == (UserPermission) id)
                {
                    return permition;
                }
            }
            return null;
        }
        #endregion

        #region Override methods
        public override string ToString()
        {
            return description;
        }
        #endregion
    }
}
